package com.calculation;
import java.util.Random;

public class Equation {
    private int operand1, operand2;
    private char operator;
    public Equation() {}
    // 带参数构造函数
    public Equation(int op1, int op2, char op) {
        this.operand1 = op1;
        this.operand2 = op2;
        this.operator = op;
    }

    public void generateRandom() {
        Random random = new Random();
        operator = random.nextBoolean() ? '+' : '-';
        if (operator == '+') {
            operand1 = random.nextInt(101);
            operand2 = random.nextInt(101 - operand1);
        } else {
            operand1 = random.nextInt(101);
            operand2 = random.nextInt(operand1 + 1);
        }
    }

    @Override
    public String toString() {
        return String.format("%d %c %d = ", operand1, operator, operand2);
    }

    // Getter方法
    public int getOperand1() { return operand1; }
    public int getOperand2() { return operand2; }
    public char getOperator() { return operator; }

    // Setter方法（用于测试）
    public void setOperand1(int op1) { this.operand1 = op1; }
    public void setOperand2(int op2) { this.operand2 = op2; }
    public void setOperator(char op) { this.operator = op; }
}